//
//  NSDate+DateFormatter.m
//  YaoHeAPP
//
//  Created by 杨亚森 on 16/6/28.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "NSDate+DateFormatter.h"

NSString *const kDateFormat = @"yyyy-MM-dd";

static NSDateFormatter *dateFormat;

@implementation NSDate (DateFormatter)

+ (NSDate *)parseDate:(NSString *)input {
    return [[self getDateFormatter] dateFromString:input];
}

+ (NSDateFormatter *)getDateFormatter {
    if (dateFormat == nil) {
        dateFormat = [[NSDateFormatter alloc] init];
        [dateFormat setDateFormat:kDateFormat];
    }
    return dateFormat;
}

+ (NSDate *)parseDate:(NSString *)input WithDateFormat:(NSString *)dateFormatString {
    dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:dateFormatString];
    return [dateFormat dateFromString:input];
}

+ (NSString *)formatDate:(NSDate *)input {
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:kDateFormat];
    return [dateFormat stringFromDate:input];
}

+ (NSString *)formatDate:(NSDate *)input WithDateFormat:(NSString *)dateFormatString {
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:dateFormatString];
    return [dateFormat stringFromDate:input];
}

@end
